package com.ruoyi.folder.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.folder.config.AliyunOSSUtils;
import com.ruoyi.folder.domain.Regis;
import com.ruoyi.folder.service.IRegisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * 注册用户列表Controller
 * 
 * @author ruoyi
 * @date 2024-10-30
 */
@RestController
@RequestMapping("/regis")
public class RegisController extends BaseController
{
    @Autowired
    private IRegisService regisService;
    @Autowired
    private AliyunOSSUtils aliyunOSSUtils;

    /**
     * 查询注册用户列表列表
     */
    @RequiresPermissions("regis:regis:list")
    @GetMapping("/list")
    public TableDataInfo list(Regis regis)
    {
        startPage();
        List<Regis> list = regisService.selectRegisList(regis);
        return getDataTable(list);
    }

    /**
     * 导出注册用户列表列表
     */
    @RequiresPermissions("regis:regis:export")
    @Log(title = "注册用户列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Regis regis)
    {
        List<Regis> list = regisService.selectRegisList(regis);
        ExcelUtil<Regis> util = new ExcelUtil<Regis>(Regis.class);
        util.exportExcel(response, list, "注册用户列表数据");
    }

    /**
     * 获取注册用户列表详细信息
     */
    @RequiresPermissions("regis:regis:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(regisService.selectRegisById(id));
    }

    /**
     * 新增注册用户列表
     */
    @RequiresPermissions("regis:regis:add")
    @Log(title = "注册用户列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Regis regis)
    {
        return toAjax(regisService.insertRegis(regis));
    }

    /**
     * 修改注册用户列表
     */
    @RequiresPermissions("regis:regis:edit")
    @Log(title = "注册用户列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Regis regis)
    {
        return toAjax(regisService.updateRegis(regis));
    }

    /**
     * 删除注册用户列表
     */
    @RequiresPermissions("regis:regis:remove")
    @Log(title = "注册用户列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(regisService.deleteRegisByIds(ids));
    }

    //图片上传下载
    @RequestMapping("fileUpload")
    public String upload(MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        InputStream inputStream = file.getInputStream();
        String s = aliyunOSSUtils.putObject(inputStream, originalFilename);
        return s;
    }
}
